<?php
class managebanner_model extends CI_Model{
	function managebanner_model(){
		parent::__construct();
	}
	
	function searchBanner($keywords){
		$strSQL = "SELECT * FROM banners a";
		
		$strSQL.= $this-> addCondition($keywords);
		
		$strSQL.= "LIMIT ".$keywords['offset'].",".$keywords['limit'];
		$result = $this->db->query($strSQL);

		if(!empty($result)){
			return $result->result();
		}
		else return array();
	}
	
	function searchTotalBanners($keywords){
		$strSQL="SELECT COUNT(*) total FROM banners a";
		$strSQL.= $this-> addCondition($keywords);		
		$result = $this->db->query($strSQL);
		if(!empty($result)) return $result->first_row()->total;
		else return 0;
	}
	
	function addCondition($keywords,$sql = null){
		$condition = " WHERE TRUE ";
		if(!empty($keywords['search_name'])){
			$condition .= " AND a.name like  ".'"%'. mysql_escape_string($keywords['search_name']). '%"';
	    }
//	    if($keywords['search_status'] != "-1"){
//	    	$condition .= " AND a.status = '" . mysql_escape_string($keywords['search_status']). "'";
//	    }
	    
		$condition .= " ORDER BY a.`id`";
		return $sql. $condition;
	}
	
}
?>